package com.wmh.baseservice.skd.mapper;

import com.wmh.baseservice.skd.pojo.SkdPickupPoint;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wmh.baseservice.skd.pojo.dto.NearbyPickupPointDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author CH
* @description 针对表【skd_pickup_point】的数据库操作Mapper
* @createDate 2023-12-28 10:15:30
* @Entity com.wmh.baseservice.skd.pojo.SkdPickupPoint
*/
public interface SkdPickupPointMapper extends BaseMapper<SkdPickupPoint> {

    /**
     * 查询自提点列表。
     *
     * @param usId 用户ID，用于筛选特定用户的自提点。
     * @param categoryId 分类ID，用于筛选特定分类的自提点。
     *                   当categoryId为null时，查询所有未逻辑删除的自提点。
     *                   当categoryId为-1时，查询categoryId为null的自提点。
     *                   当categoryId为0时，查询逻辑删除的自提点。
     *                   当categoryId为其他值时，查询对应categoryId的自提点。
     * @return 符合条件的自提点列表。
     */
    @Select("<script>"
            + "SELECT * FROM skd_pickup_point "
            + "WHERE us_id = #{usId} "
            + "<if test='categoryId != null'>"
            + "<if test='categoryId == -1'>"
            + "AND category_id IS NULL "
            + "</if>"
            + "<if test='categoryId == 0'>"
            + "AND deleted = 1 "
            + "</if>"
            + "<if test='categoryId != -1 and categoryId != 0'>"
            + "AND category_id = #{categoryId} "
            + "</if>"
            + "</if>"
            + "<if test='categoryId == null'>"
            + "AND deleted = 0 "
            + "</if>"
            + "<if test='queryName != null and !queryName.isEmpty()'>"
            + "AND name LIKE CONCAT('%', #{queryName}, '%') "
            + "</if>"
            + "</script>")
    List<SkdPickupPoint> queryPickupPoints(@Param("usId") Long usId,
                                           @Param("queryName") String queryName,
                                           @Param("categoryId") Integer categoryId);

    /**
     * 根据经纬度获取附近自提点
     * @param lat 经度
     * @param lng 纬度
     * @return 返回自提点id列表
     */
    List<NearbyPickupPointDTO> getNearbyPickupPoints(@Param("lat") String lat, @Param("lng") String lng);
}




